#pragma once
#include <condition_variable>
#include <mutex>
#include <queue>
#include <functional>
#include "../message/interface/MessageInterface.hpp"


template<typename MESSAGE_TYPE>
class MessageProcessorTool {

private:
    class MessageQueue {
    private:
        std::mutex m_mutex;
        std::queue<MessageInterface<MESSAGE_TYPE>*> m_messageQueue;
        std::condition_variable m_conditionVariable;
        std::function<bool()> m_handleFun;
        bool m_handled;

    public:
        /**
         *
         * @param handleFun
         */
        MessageQueue(std::function<bool()> handleFun) {
            this->m_handleFun = handleFun;
            this->m_handled = false;
        }

        ~MessageQueue() {}

        /**
         * 启动处理
         */
        void handle() {
            if (!this->m_handled) return;
            std::unique_lock<std::mutex> lock(this->m_mutex);
            if (!this->m_handled) return;
            while (this->m_handled) {
                this->m_conditionVariable.wait(lock,[this](){return this->m_messageQueue.empty();});
                this->m_handleFun();
            }

        }

    };
private:

public:


};